package com.training.micrservices.eureka.openfeign;

import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

@FeignClient(value = "micrservice-eureka-client",
        configuration = EurekaClientFeign.MultipartSupportConfig.class)
public interface EurekaClientFeign {

    @GetMapping("/eureka/hello")
    String hello();

    /**
     * 文件上传
     *
     * @param file 文件流
     * @return URL
     */
    @RequestMapping(value = "/eureka/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    String upload(@RequestPart("fileList") MultipartFile file);

    class MultipartSupportConfig {

        @Bean
        public Encoder feignFormEncoder() {
            return new SpringFormEncoder();
        }
    }
}